You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix deserializing a null smart pointer not clearing the target - #8181
serialize_pointer_tracked (input archive): reset the target (ptr.reset()) when the archived pointer is null, instead of leaving the old value in place.
serialize_pointer_untracked (input archive): assign Pointer(nullptr) in the null case. This also covers raw_ptr_type, which has no reset().
Add test_shared_null_clears_target and test_unique_null_clears_target to serialization_smart_ptr.cpp.
Any background context you want to provide?
Both load functions read the valid flag and only acted if (valid). Loading a null pointer into a target that already held a value therefore did nothing and the stale value survived. This is the same class of bug as the earlier list/deque fix (load must replace the existing content).
Both new tests fail without the change and pass with it. The serialization unit tests pass.
Checklist
Not all points below apply to all pull requests.
I have added a new feature and have added tests to go along with it.
I have fixed a bug and have added a regression test.
I have added a test using random numbers; I have made sure it uses a seed, and that random numbers generated are valid inputs for the tests.
No actionable comments were generated in the recent review.
Summary
Summary by CodeRabbit
Bug Fixes
Deserializing a null smart pointer now clears an existing value, rather than leaving the previous value intact. This applies to both tracked and untracked pointers.
Added coverage for this behavior with shared and unique pointers, confirming that deserializing a null value clears a non-null target.
When a serialized pointer is null, tracked and untracked deserialization now clear the destination. Tests verify this behavior for non-null std::shared_ptr<int> and std::unique_ptr<int> targets.
Changes: Null pointer deserialization
Layer / File(s)
Summary
Clear targets for null pointers libs/core/serialization/include/hpx/serialization/detail/pointer.hpp, libs/core/serialization/tests/unit/serialization_smart_ptr.cpp
Tracked deserialization resets the destination when the validity flag is false. Untracked deserialization assigns a null pointer. Tests verify that loading null shared and unique pointers clears non-null targets.
Deserializing a null pointer now leaves the target null, as the linked issue requests. Tests cover shared and unique pointers. No concrete merge-blocking risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title states the main change: deserializing a null smart pointer now clears the existing target. The raw summary and objectives confirm the change resets the target in the input-archive pointer de…
Description check
The description explains the change. It names the two modified load functions, serialize_pointer_tracked and serialize_pointer_untracked, and the new tests. It also gives the root cause, where the cod…
Linked Issues check
[#8179] requires that loading a serialized null smart pointer from an input_archive leaves the existing target null, for std::shared_ptr (tracked path) and std::unique_ptr (untracked path). Diff from …
Out of Scope Changes check
The whole-PR diff from merge base 3af219b to head c584889 changes two files: libs/core/serialization/include/hpx/serialization/detail/pointer.hpp and libs/core/serialization/tests/unit/serializa…
Full details: Title check
Explanation
The title states the main change: deserializing a null smart pointer now clears the existing target. The raw summary and objectives confirm the change resets the target in the input-archive pointer deserialization paths, so the title matches the changeset.
Full details: Description check
Explanation
The description explains the change. It names the two modified load functions, serialize_pointer_tracked and serialize_pointer_untracked, and the new tests. It also gives the root cause, where the code acted only when the valid flag was set, and links issue #8179.
Full details: Linked Issues check
Explanation
[#8179] requires that loading a serialized null smart pointer from an input_archive leaves the existing target null, for std::shared_ptr (tracked path) and std::unique_ptr (untracked path). Diff from merge base 3af219b to head c584889 for pointer.hpp adds an else branch to serialize_pointer_tracked (ptr.reset()) and to serialize_pointer_untracked (ptr = Pointer(nullptr)). The valid-true paths are unchanged. The untracked assignment also covers raw_ptr_type, which has no reset(). The diff for serialization_smart_ptr.cpp adds test_shared_null_clears_target and test_unique_null_clears_target. Each test serializes a null pointer, loads it into a non-null target, and checks HPX_TEST(!target). Both tests are called from main. The author reports that both tests fail without the change and pass with it. I did not build or run them. The issue requires no non-coding work.
Full details: Out of Scope Changes check
Explanation
The whole-PR diff from merge base 3af219b to head c584889 changes two files: libs/core/serialization/include/hpx/serialization/detail/pointer.hpp and libs/core/serialization/tests/unit/serialization_smart_ptr.cpp. The header hunks are the two else branches required by #8179. The test hunks add two regression tests for the same null-into-non-null case for shared_ptr and unique_ptr. The changes since the previous reviewed head (980335e) are consistent with this scope. No unrelated changes appear in the reviewed evidence.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer TIP This summary will be updated as you push new changes.
The reason will be displayed to describe this comment to others. Learn more.
Thanks, the fix is right. It conflicts with master now in serialization_smart_ptr.cpp (tests added there by #8144), could you please rebase? Then this is good to go.
serialize_pointer_tracked and serialize_pointer_untracked only acted when the archived pointer was valid, so loading a null pointer into a target that already held a value left that value in place. Reset the target in the null case and add tests for std::shared_ptr and std::unique_ptr.
FixesTheHPXProject#8179
Signed-off-by: Vaatsalya Srivastava <vaatsalyasrivastava_ee_25a19036@dtu.ac.in>
Thanks, Rebased on master and resolved the conflict in serialization_smart_ptr.cpp; the new tests from #8144 and mine are both kept. Please note that master currently fails to build in preprocess_keep_alive.cpp / post_receive_actions.cpp (extra_data_id_type is now numeric); #8188 fixes that, so CI here should go green once it lands. I also verified locally with #8188 applied: serialization_smart_ptr_test passes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8179
Proposed Changes
serialize_pointer_tracked(input archive): reset the target (ptr.reset()) when the archived pointer is null, instead of leaving the old value in place.serialize_pointer_untracked(input archive): assignPointer(nullptr)in the null case. This also coversraw_ptr_type, which has noreset().test_shared_null_clears_targetandtest_unique_null_clears_targettoserialization_smart_ptr.cpp.Any background context you want to provide?
Both load functions read the
validflag and only actedif (valid). Loading a null pointer into a target that already held a value therefore did nothing and the stale value survived. This is the same class of bug as the earlier list/deque fix (load must replace the existing content).Both new tests fail without the change and pass with it. The serialization unit tests pass.
Checklist
Not all points below apply to all pull requests.